package com.hkts.management.common.mq;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassNameFanoutRabbitConfig
 * @Description
 * @Author yck
 * @Date2021-04-26 11:07
 * @Version V1.0
 **/

@Configuration
public class FanoutRabbitConfig {
    /**
     *  创建三个队列 ：fanout.A   fanout.B  fanout.C
     *  将三个队列都绑定在交换机 fanoutExchange 上
     *  因为是扇型交换机, 路由键无需配置,配置也不起作用
     */
    //exchange name
    public static final String BROADCASTEXCHANGE = "broadcastExchange";
    //司机往货主端推送模板消息
    public static final String Reminders_Queue_Name = "reminders.queue";
    public static final String CARGOEXCHANGE="CarExchange";
    //货主推送司机模板消息
    public static final String ASSIFN="fanout.assign";
    public static final String FANOUTEXCHANGE="fanoutExchange";
    /*
     * 催单交换器Reminders
     * */
/*    @Bean
    DirectExchange directExchange(){
        return new DirectExchange(FanoutRabbitConfig.Reminders_Exchange_Name);
    }
    @Bean
    public Queue queueReminders() {
        return new Queue(FanoutRabbitConfig.Reminders_Queue_Name);
    }
    @Bean
    Binding bindingReminders(){
        return  BindingBuilder.bind(queueReminders()).to(directExchange()).with(FanoutRabbitConfig.Reminders_Exchange_Name);
    }*/
    @Bean
    public Queue queueReminders() {
        return new Queue(Reminders_Queue_Name);
    }


    @Bean
    FanoutExchange carExchange() {
        return new FanoutExchange(CARGOEXCHANGE);
    }
    @Bean
    Binding bindingExchangeReminders() {
        return BindingBuilder.bind(queueReminders()).to(carExchange());
    }
    @Bean
    public Queue queueAssign() {
        return new Queue(ASSIFN);
    }
    @Bean
    FanoutExchange fanoutExchange() {
        return new FanoutExchange(FANOUTEXCHANGE);
    }
    @Bean
    Binding bindingExchangeAssign() {
        return BindingBuilder.bind(queueAssign()).to(fanoutExchange());
    }
    @Bean
    FanoutExchange broadcastExchange() {
        return new FanoutExchange(BROADCASTEXCHANGE);
    }
    @Bean
    Binding broadcastExchangeAssign() {
        return BindingBuilder.bind(queueAssign()).to(broadcastExchange());
    }
    @Bean
    Binding broadcastExchangeReminders() {
        return BindingBuilder.bind(queueReminders()).to(broadcastExchange());
    }
}
